<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .box {
      width: 800px;
      margin: auto;
    }

    .box .content {
      width: 100%;
      height: 350px;
      border: 1px solid #ccc;
      margin: 20px auto;
      padding: 10px;
      box-sizing: border-box;
    }

    .box .content li {
      margin: 10px 0;
      padding: 5px;
      line-height: 2;
      border-radius: 5px;
      clear: both;
    }

    .box textarea {
      height: 80px;
      display: block;
      margin: auto;
      margin-top: 20px;
      width: 100%;
    }

    .box button {
      width: 80px;
      height: 30px;
      border: 1px solid #ccc;
      float: right;
      margin-top: 10px;
    }

    .active {
      float: right;
      background-color: #fc0;
      color: #fff;
    }

    p {
      color: #ccc;
      font-size: 12px;
    }
  </style>
</head>

<body>
  <div class="box">
    <ul class="content"></ul>
    <textarea name="" id="text" cols="30" rows="10"></textarea>
    <button id="btn">发送</button>
    <p>温馨提示：按 ctrl + shift键也可以发送消息哟</p>
  </div>

  <script>
    //需求：点击发送，然后拿到文本域的内容，赋值给小li(动态创建小li)，并且右浮动
    let ul = document.querySelector("ul")
    let txt = document.querySelector("#text")
    let btn = document.querySelector("#btn")

    btn.onclick = function () {
      render()
    }

    //需求2：点击 按 ctrl + shift键也可以发送消息哟
    window.onkeydown = function (e) {
      // console.dir(e)
      if (e.ctrlKey && e.shiftKey) {
        if (txt.value !== "") {
          render()
        } else {
          alert("请输入内容")
        }
      }
    }

    function render() {
      //01：先动态创建li
      let li = document.createElement("li")
      li.innerHTML = txt.value
      li.className = "active"
      ul.appendChild(li)
      txt.value = ""
    }
  </script>
</body>

</html>